<template>
  <el-container class="home_container">
    <!-- 头部 -->
    <el-header>
      <div>
        <div class="logo">
          <img src="http://lh188.xyz/imgFiles/bms-img/zhm.jpg" />
        </div>
        <span>电商后台管理系统</span>
      </div>
      <el-button type="danger" @click="signOut">注销</el-button>
    </el-header>
     <!-- 主体 -->
    <el-container>
      <!-- 侧边栏 -->
      <el-aside :width="isCollapse ? '64px':'200px'">
        <div class="toggle-button" @click="toggleCollapse">|||</div>
        <!-- 侧边栏菜单 -->
        <el-menu :unique-opened="true" :router="true" :collapse-transition="false" :collapse="isCollapse" text-color="#f40" active-text-color="#409eff">
               <!-- 一级菜单 -->
              <el-submenu v-for="item in menuList" :key="item.id" :index="item.id + ''">
                <!-- 一级菜单模板区 -->
                <template slot="title">
                  <!-- 图标 -->
                  <i :class="iconsObj[item.id]"></i>
                  <!-- 文本 -->
                  <span>{{ item.authName }}</span>
                </template>
                <!-- 二级菜单 -->
                <el-menu-item :index="'/'+ subItem.path" v-for="subItem in item.children" :key="subItem.id">
                  <template slot="title">
                    <!-- 图标 -->
                    <i class="el-icon-menu"></i>
                    <!-- 文本 -->
                    <span>{{ subItem.authName }}</span>
                  </template>
                </el-menu-item>
              </el-submenu>
            </el-menu>
      </el-aside>
      <!-- 右侧内容 -->
      <el-main>
        <!-- 路由占位符 -->
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>
<script>
export default {
  data () {
    return {
      // 左侧菜单栏数据
      menuList: [],
      iconsObj: {
        125: 'iconfont icon-user',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      // 是否折叠
      isCollapse: false
    }
  },
  created () {
    this.getMenuList()
  },
  methods: {
    signOut () {
      // 清空token
      window.sessionStorage.clear()
      // 跳转
      this.$router.push('/login')
    },
    // 获取菜单栏信息
    async getMenuList () {
      const { data: res } = await this.$http.get('menus')
      if (res.meta.status !== 200) return this.$msg.error(res.meta.msg)
      this.menuList = res.data
    },
    toggleCollapse () {
      this.isCollapse = !this.isCollapse
    }
  }
}
</script>

<style lang="less" scoped="scoped">
  .el-button{
    position: absolute;
    right: 20px;
    top: 10px;
    opacity: 0.8;
  }
  .el-header {
    background: #544a7d;
    background: -webkit-linear-gradient(to right, #544a7d, #ffd452);
    background: linear-gradient(to right, #544a7d, #ffd452);
    display:flex ;
    justify-content: space-between;
    align-items: center;
    padding-left: 0;
    font-size: 20px;
    color: #eee;
    .el-button{
      margin-right: 15px;
    }
    div {
      display: flex;
      align-items: center;
      span{
        margin-left: 15px;
      }
    }
  }
  .el-container {
    height: 100%;
  }
  .el-main {
    // background: #659999;
    // background: -webkit-linear-gradient(to left, #659999, #f4791f);
    // background: linear-gradient(to left, #659999, #f4791f);
  }
  .el-aside{
    background: linear-gradient(to left, #780206, #061161);
    .el-menu{
      border-right: none;
      background: linear-gradient(to left, #780206, #061161);
      font-weight: 700;
      .el-menu-item{
        background: linear-gradient(to left, #780206, #061161);
      }
    }
  }
  .iconfont {
    margin-right: 10px;
  }
  .toggle-button{
    font-size: 10px;
    background: linear-gradient(to right, #659999, #f4791f);
    color: #eee;
    line-height: 24px;
    text-align: center;
    letter-spacing: 0.2rem;
    cursor: pointer;
  }
  .logo{
    width: 80px;
    height: 60px;
    border-radius: 50%;
    overflow: hidden;
    img{
      width: 100%;
      height: 100%;
    }
  }
</style>
